import { Module, Dependencies } from '@nestjs/common';
import { AppController } from './app.controller';
import { TypeOrmModule } from '@nestjs/typeorm';
import { DataSource } from 'typeorm';
import { options } from './common/constants/mysql.setting';
import { AdminModule } from './admin/admin.module';
import { BlogModule } from './blog/blog.module';
import { ExperimentModule } from './experiment/experiment.module';
import { UploadModule } from './upload/upload.module';
import { ArticleCommentModule } from './article-comment/article-comment.module';

@Dependencies(DataSource)
@Module({
  imports: [
    TypeOrmModule.forRoot({
      ...options,
      // 扫描本项目中.entity.ts或者.entity.js的文件
      entities: [
        __dirname + '/entities/*.entity{.ts,.js}',
        __dirname + '/entities/admin/*.entity{.ts,.js}',
        __dirname + '/entities/blog/*.entity{.ts,.js}',
      ],
    }),
    AdminModule,
    BlogModule,
    ExperimentModule,
    UploadModule,
    ArticleCommentModule,
  ],
  controllers: [AppController],
})
export class AppModule {
  constructor(private readonly dataSource: DataSource) {}
}
